// pages/center/clock-in/clock-in-record/clock-in-record.js
var app = getApp();
var verify = require('../../../../utils/verify-token.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    List: [],
    page: 0,
    totalPage: 0,
    loaded: false,
    loading: false,
    nolist: true,
    inputShowed: true,
    filterValue: '',
    inputVal: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      sh: app.globalData.screenHeight,
      sw: app.globalData.screenWidth,

    })
  },
  getList(){
    var thm = this;
    var dat = {     
      searchContent: thm.data.filterValue,
      size: 10,
      page: thm.data.page
    };
    wx.request({
      url: app.globalData.baseUrl + 'clock_in_record/applet/current_user/list',
      method: 'get',
      header: {
        'AUTHORIZATION': app.globalData.token
      },
      data: dat,
      success: function (res) {
        if (res.data.code == 60006) {
          verify.clearAll()
        } else if (res.data.code == 200) {
          var listdata = res.data.data.content;
          var listD = thm.data.List;
          var ldh = listD.length;
          for (var i = 0; i < listdata.length; i++) {
            listD[ldh + i] = listdata[i]
          }
          thm.setData({
            List: listD,
            totalPage: res.data.data.totalPages,
            loading: res.data.data.last ? false : true,
            loaded: res.data.data.last ? true : false
          })

        } else {
          wx.showModal({
            title: '操作失败',
            content: res.data.message,
          })
        }
      }
    })
  },

  detail: function (ev) {
    wx.navigateTo({
      url: 'clin-record-detail/clin-record-detail?data=' + ev.currentTarget.id,
    })
  },

  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  // 取消搜索
  hideInput: function () {
    this.setData({
      inputShowed: false,
      filterValue: '',
      inputVal: ''
    });
    this.search();
  },
  inputTyping: function (e) {
    this.setData({
      filterValue: e.detail.value
    });
    this.search();
  },


  // 搜索框输入
  input: function (res) {
    this.setData({
      filterValue: res.detail.value
    })
  },
  // 查询故障
  search: function () {
    var filterValue = this.data.filterValue;
    this.setData({
      filterValue: filterValue,
      List: [],
      page: 0,
      totalPage: 0,
    })
    this.getList()
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var filterValue = that.data.filterValue;
    that.setData({
      List: [],
      page: 0,
      totalPage: 0,
      filterValue: filterValue
    });
    that.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page = that.data.page + 1;
    if (page <= that.data.totalPage - 1) {
      that.setData({
        page: page,
        filterValue: that.data.filterValue
      })
      that.getList();
    } else {
      that.setData({
        loaded: true,
        loading: false,
        filterValue: that.data.filterValue
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})